<template>
  <div class="preWorkBox">
    <!-- 序列号替换-->
    <div class="content">
      <div class="contentDiv" v-if="submitShow == false">
        <el-form
          ref="form"
          :model="form"
          class="perForm"
          label-width="auto"
          size="medium"
        >
          <el-form-item label="SN码:" prop="sn">
            <el-input
              id="head-input"
              v-model="form.snCode"
              type="textarea"
              placeholder="请输入SN码"
              :autosize="{ minRows: 2, maxRows: 5 }"
              style="width: 400px; height: 50px"
              @keydown.enter.native="snbutton"
            />
          </el-form-item>
        </el-form>
      </div>

      <div v-if="submitShow" style="width: 60vw">
        <span>物料列表</span>
        <el-table
          :data="materialList"
          row-key="materialList"
          style="margin-top: 20px"
        >
          <el-table-column
            label="物料编号"
            width="150"
            align="center"
            prop="itemCode"
          />
          <el-table-column
            label="物料名称"
            width="150"
            align="center"
            prop="itemName"
          />
          <el-table-column
            label="物料规格"
            width="150"
            align="center"
            prop="specification"
          />
          <el-table-column
            label="数量"
            width="150"
            align="center"
            prop="jdyNumerator||quantity"
          >
            <template slot-scope="scope">
              {{
                scope.row.jdyNumerator + scope.row.unitOfMeasure ||
                scope.row.quantity + scope.row.unit
              }}
            </template>
          </el-table-column>
          <el-table-column
            label="物料序列号"
            width="150"
            align="center"
            prop="sequenceCode"
          >
            <template slot-scope="scope">
              <el-input v-model="scope.row.sequenceCode" />
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="dialog_footer">
      <el-button
        v-if="submitShow"
        type="primary"
        style="font-size: 24px"
        @click="submit"
        >提 交</el-button
      >
    </div>
  </div>
</template>
        
      <script>
// failsafeList  13008
import { submitSerialReplace, getSerialReplace } from "@/api/apppro/index";
export default {
  name: "DebuggingStation",
  props: {
    formObj: Object,
  },
  data() {
    return {
      form: {},
      loading: false,
      templateList: [],
      stationCheckExamineList: [],
      stationCheck: {},

      //物料列表是否展示
      submitShow: false,
      //物料列表数组
      materialList: [],
    };
  },

  created() {
    // this.getCode();
    // this.getList();
  },
  methods: {
    getList() {},
    //根据sn码查询工单信息
    snbutton() {
      let params = {
        snCode: this.form.snCode,
        processId: this.formObj.processId,
        workorderCode: this.formObj.workorderCode,
        workorderId: this.formObj.workorderId,
      };
      getSerialReplace(params).then((res) => {
        console.log(res, "查询的res");
        if (res.code == 200) {
          this.submitShow = true;
          this.materialList = res.data;
        }
      });
    },
    //提交
    submit() {
        // this.materialList.forEach((item,index)=>{
        //     if(this.materialList[index].itemCode ==this.materialList[index+1].itemCode ){
        //         console.log("33");
        //     }
        // })
        // for (let i = 0; i < this.materialList.length ; i++) {
        //   if(this.materialList[i].itemCode == this.materialList[i+1].itemCode ){
        //       this.materialList[i].sequenceCode += ',' + this.materialList[i+1].sequenceCode
        //       this.materialList.splice(i+1,1)
        //   }
        // }
        // console.log(this.materialList,'this.materialList222');
        // return 
      submitSerialReplace(this.materialList).then((res) => {
        console.log(res, "提交的res");
        if (res.code == 200) {
          this.$modal.msgSuccess(res.msg);
        }
      });
    },
  },
};
</script>
      <style rel="stylesheet/scss" lang="scss" scoped>
.perForm ::v-deep .el-form-item__label {
  font-size: 28px;
}

.contentDiv ::v-deep .el-alert__title {
  font-size: 20px;
}
.contentDiv ::v-deep .el-alert__icon {
  font-size: 20px;
}
.content {
  // margin-top: 20px;
  // text-align: center;
  display: flex;
  justify-content: center;
  // width: 100%;
}

.dialog_footer {
  width: 100%;
  text-align: center;
  margin-top: 20px;
  // display: flex;
  // justify-content: center;
}

.sn_box {
  text-align: left;
  margin-left: 10%;
  font-size: 20px;
  line-height: 40px;
}

::v-deep input::-webkit-outer-spin-button,
::v-deep input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
::v-deep input[type="number"] {
  -moz-appearance: textfield;
}
</style>
        